package com.derek.omshopping.utils;/**
 * Created by ThinkPad on 2016/10/21.
 */

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;

/**
 * 通过包管理器实现类，来获取包信息
 * 作者：ThinkPad on 2016/10/21 12:47
 * 邮箱：212740182@qq.com
 */
public class PackageUtils {


    /**
     * 获取当前软件的versionName和versioncode
     *
     * @param context
     * @return
     */
    public static String getAppVersionName(Context context) {
        String versionName = "";
        int versioncode = 0;
        try {
            // ---get the package info---
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            versionName = pi.versionName;
            versioncode = pi.versionCode;
            Log.d("IVEN", "versionName= " + versionName + "---" + "versioncode=" + versioncode);
            if (versionName == null || versionName.length() <= 0) {
                return "";
            }
        } catch (Exception e) {
            Log.e("VersionInfo", "Exception", e);
        }
        return versionName;
    }


}

